package com.example.demo.utils;

/**
 * 页面包装类
 */
public class Page {
    //当前页面
    private int pageNo = 1;
    //每页显示数量
    private int pageSize = 10;
    //总数
    private long totalCount = 0;
    //总页数
    private int totalPage = 1;

    public long getTotalPage() {
        return totalCount % pageSize == 0 ? totalCount / pageSize : totalCount / pageSize + 1;
    }

    public int limitStart() {
        return pageSize * (getPageNo() - 1);
    }

    public int limitEnd() {
        return pageSize;
    }

    public int getPageNo() {
        if(pageNo > getTotalPage()) {
            return totalPage;
        }
        return pageNo;
    }

    public Page setPageNo(int pageNo) {
        this.pageNo = pageNo;
        return this;
    }

    public int getPageSize() {
        return pageSize;
    }

    public Page setPageSize(int pageSize) {
        this.pageSize = pageSize;
        return this;
    }

    public long getTotalCount() {
        return totalCount;
    }

    public Page setTotalCount(long totalCount) {
        this.totalCount = totalCount;
        return this;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }



//    Map map = Maps.newHashMap();
//    vo.setPageNo(pageNo);
//    vo.setPageSize(pageSize);
//    Page page = new Page().setPageNo(pageNo).setPageSize(pageSize);//创建page类
//    map.put("orderList",listback);
//    map.put("page",page);



    //listback如下：
//     listOrderPackage.addAll(listOrder);
//        Collections.sort(listOrderPackage, new Comparator<Map<String, Object>>() {
//        public int compare(Map<String, Object> o1, Map<String, Object> o2) {
//            Date deleteTime1 = new Date();
//            Date deleteTime2 = new Date();
//            try {
//                SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
//                deleteTime1 = sdf.parse(o1.get("deleteTime").toString());
//                deleteTime2 = sdf.parse(o2.get("deleteTime").toString());
//            } catch (ParseException e) {
//                e.printStackTrace();
//            }
//            return DateUtils.compareDate(deleteTime1, deleteTime2);
//        }
//    });
//        page.setTotalCount(listOrderPackage.size());
//    List<Map<String, Object>> subList = listOrderPackage.subList(vo.getPageSize() * (vo.getPageNo() - 1), ((vo.getPageSize() * vo.getPageNo()) > listOrderPackage.size() ? listOrderPackage.size() : (vo.getPageSize() * vo.getPageNo())));
}
